using System;
using System.Text;
namespace ns4
{
	public sealed class BitMatrix
	{
		public int width;
		public int height;
		public int rowSize;
		public int[] bits;
		public int Width
		{
			get
			{
				return this.width;
			}
		}
		public int Height
		{
			get
			{
				return this.height;
			}
		}
		public int Dimension
		{
			get
			{
				if (this.width != this.height)
				{
					throw new SystemException("Can't call getDimension() on a non-square matrix");
				}
				return this.width;
			}
		}
		public bool Renamed
		{
			get
			{
				int num = int_1 * this.rowSize + (int_0 >> 5);
				return (SupportClass.URShift(this.bits[num], int_0 & 31) & 1) != 0;
			}
		}
		public int Renamed
		{
			set
			{
				int num = value * this.rowSize + (int_0 >> 5);
				this.bits[num] |= 1 << int_0;
			}
		}
		public BitMatrix(int dimension) : this(dimension, dimension)
		{
		}
		public BitMatrix(int width, int height)
		{
			if (width < 1 || height < 1)
			{
				throw new ArgumentException("Both dimensions must be greater than 0");
			}
			this.width = width;
			this.height = height;
			int num = width >> 5;
			if ((width & 31) != 0)
			{
				num++;
			}
			this.rowSize = num;
			this.bits = new int[num * height];
		}
		public void flip(int int_0, int int_1)
		{
			int num = int_1 * this.rowSize + (int_0 >> 5);
			this.bits[num] ^= 1 << int_0;
		}
		public void clear()
		{
			int num = this.bits.Length;
			for (int i = 0; i < num; i++)
			{
				this.bits[i] = 0;
			}
		}
		public void setRegion(int left, int int_0, int width, int height)
		{
			if (int_0 < 0 || left < 0)
			{
				throw new ArgumentException("Left and top must be nonnegative");
			}
			if (height < 1 || width < 1)
			{
				throw new ArgumentException("Height and width must be at least 1");
			}
			int num = left + width;
			int num2 = int_0 + height;
			if (num2 > this.height || num > this.width)
			{
				throw new ArgumentException("The region must fit inside the matrix");
			}
			for (int i = int_0; i < num2; i++)
			{
				int num3 = i * this.rowSize;
				for (int j = left; j < num; j++)
				{
					this.bits[num3 + (j >> 5)] |= 1 << j;
				}
			}
		}
		public BitArray getRow(int int_0, BitArray bitArray_0)
		{
			if (bitArray_0 == null || bitArray_0.Size < this.width)
			{
				bitArray_0 = new BitArray(this.width);
			}
			int num = int_0 * this.rowSize;
			for (int i = 0; i < this.rowSize; i++)
			{
				bitArray_0.setBulk(i << 5, this.bits[num + i]);
			}
			return bitArray_0;
		}
		public override string ToString()
		{
			StringBuilder stringBuilder = new StringBuilder(this.height * (this.width + 1));
			for (int i = 0; i < this.height; i++)
			{
				for (int j = 0; j < this.width; j++)
				{
					stringBuilder.Append(this.get_Renamed(j, i) ? "X " : "  ");
				}
				stringBuilder.Append('\n');
			}
			return stringBuilder.ToString();
		}
	}
}
